package com.moon.controller;

import com.moon.entity.Admin;
import com.moon.entity.Student;
import com.moon.utils.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/other")
public class OtherController extends BaseController {
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/commitDate")
    @ResponseBody
    public String commitDate(Student st) {
        System.out.println("dt=" + st.getBirth());
        return "success";
    }

    //远程调用
    @RequestMapping("/call")
    @ResponseBody
    public String call() {
        String api = "http://localhost:8080/web_war_exploded/employees"; //访问servlet项目
        String str = restTemplate.getForObject(api, String.class);
        return str;
    }

    //远程调用  cake项目调用bread项目
    @RequestMapping("/callBread")
    @ResponseBody
    public List<Admin> selectAll(){
        String api="http://localhost:8001/admin/selectAll";
        List<Admin> list=restTemplate.getForEntity(api,List.class).getBody();
        return list;
    }
}